< previous page page_217 next page >

Page 217
Breakpoints are lines of code designated to put Visual Basic in break mode before they execute. By using breakpoints, you can run the program normally and then stop execution and begin stepping through code at the desired location.
To set a breakpoint, highlight the line of code you want in design mode, and then press F9 or choose Debug, Toggle Breakpoint. Visual Basic highlights the breakpoint, and a circle appears in the margin, as shown in Figure 10.2.
0217-01.jpg
Figure 10.2
Breakpoints allow you to execute
a program up to a certain line; you can
then examine a variable value and
continue running to the next breakpoint.
Now, test a breakpoint with the sample code. Set a breakpoint on the End statement by clicking it and pressing F9. Next, click the VB Start button (or press F5) like you are running the program normally. It should execute the While loop and then automatically enter break mode. Print the value of i (it should be 101) to verify that the While loop did indeed execute. Then press F5 to continue execution, and the End statement should stop the program.
Working in the Immediate Window
The Immediate window, also known as the Debug window, provides a way for you to enter code statements while a program is in break mode. To display the window, make sure that the program is in break mode, and press Ctrl+G. To restart the program, simply press F5 or step to the next line of code.
Some common uses of the Immediate window are demonstrated in Figure 10.3.
0217-02.jpg
Figure 10.3
You can copy and paste statements from the Code
window to the Immediate window to execute them manually.
Figure 10.3 demonstrates assigning a variable to a value and calling a program function manually. You can also end the program prematurely by typing End into the Immediate window.

 
< previous page page_217 next page >